import * as request from '../constant/fetch-request'
import HTTP_CODE from '../constant/http-code'

export const getAssignmentQuizTagsByProgramId = (programId) => {
  return dispatch => {
    (async () => {
      const res = await request.get(`../api/programs/${programId}/assignmentQuizTags`)
      if (res.status === HTTP_CODE.OK) {
        dispatch({
          type: 'GET_ALL_ASSIGNMENT_QUIZ_TAGS',
          data: res.body
        })
      }
    })()
  }
}
export const getStudentAssignmentQuizTags = (assignmentId, quizId, studentId) => {
  return dispatch => {
    (async () => {
      const res = await request.get(`../api/assignments/${assignmentId}/quizzes/${quizId}/students/${studentId}/userAssignmentQuizTags`)
      if (res.status === HTTP_CODE.OK) {
        dispatch({
          type: 'GET_STUDENT_ASSIGNMENT_QUIZ_TAG',
          data: res.body
        })
      }
    })()
  }
}
export const editStudentAssignmentQuizTags = (assignmentId, quizId, studentId, tagIds) => {
  return dispatch => {
    (async () => {
      const res = await request.update(`../api/assignments/${assignmentId}/quizzes/${quizId}/students/${studentId}/userAssignmentQuizTags`, tagIds)
      if (res.status === HTTP_CODE.NO_CONTENT) {
        dispatch(getStudentAssignmentQuizTags(assignmentId, quizId, studentId))
      }
    })()
  }
}
